

Changing the foreground and the background colors of the charac-
ter sets of table 2 is performed by this subroutine.  If you  set 
variable  (us) to the character set code (table 1),  and set (uf) 
and  (ub) to the foreground and background color codes  found  in 
table 2,  and lastly execute a GOSUB 55000 the characters in that 
set will change to the corresponding colors.

FORMAT:
10 us=9: uf=1: ub=15: GOSUB 55000

PEEK VDP MEMORY UTILITY (GOSUB 56000)

This  utility will allow you to peek at any VDP memory  location. 
If  you  set (ua) to the address you wish to peek and  perform  a 
GOSUB  56000 you Will have the contents of that address  returned 
to you in the variable (ub).

FORMAT:
10 ua=2144: GOSUB 56000: va=ub

Page - 9

SCREEN COLOR UTILITY (GOSUB 57000)

This  utility  will  let you change the background color  of  the 
screen. By setting (us) to the desired color code number found in 
table  3 and performing a GOSUB 57000 you will set the screen  to 
the corresponding color.

FORMAT:
10 us=5: GOSUB 57000

READING FROM THE SCREEN (GOSUB 58000)

This subroutine allows you to read a character off the screen  at 
any location.  Variable (ur) is used to hold the row location and 
varialble  (ul)  is  set to contain the column  location  on  the 
screen  you  wish to obtain.   After you execute GOSUB 58000  the 
variable (ub) will contain the ASCII code of that location.

FORMAT: 10 ur=10: ul=20: GOSUB 58000: va=ub

UNSCRAMBLING A MESS !!!

Probably  the most important command in SMARTBASIC is 	"TEXT".  
This command will undo anything you have
done  to  the  VDP memory and allows you to start  with  a  clean 
slate.   There  will be times when the screen is  totally  blank, 
giving you the impression that the VDP hung up.  If you have been 
accessing  the  VDP,  its worth trying "TEXT" even if  you  don't 
think you did anything wrong.   It resets all the table locations 
and content, including the
character definition table.

BASIC UTILITES

This  utility  package should be included below all  the  example 
programs  to follow.   There are a large number of REM statements 
in the following program. If you would like to save yourself time 
and CPU memory you can leave them out as you type in the programs

Make  certain  the  last REM statement in the  utilities  is  not 
removed.

Listing #1

50990  REM Set up assembly routine
50995  REM  Data for loading down machine code  for  POKEVM  See: 
       Assembly listing
51000 DATA 245,197,1,0,0,62,0,211,191,62,0,211,191,227,227,227,
      227,227,227,62,0,211,190,11,120,177,32,247,193,241,201
51005 	REM Machine code for PEEPV
51010 DATA 245,62,0,211,191,62,0,211,191,227,227,227,227,0,0,
      219,190,50,0,0,241,201,0,0,0,0,0,0,0,0
51015 REM Get address of last line number
51100 ux = PEEK(16102)*256+PEEK(16101)-2
51150 REM Get address of last line of tokenized code
51200 ux = PEEK(ux)+PEEK(ux+1)*256-10
51250 REM Load down machine code
51300 FOR ui = ux TO ux-56: READ ua: POKE ui, ua: NEXT ui
51350 REM Calculate and POKE down address for LD $0000,A of 
      PEEKV assembly routine
51400 ut = ux-55: POKE ux-50, INT(ut/256): POKE ux+49,
      ut-INT(ut/256)*256
51500 RETURN
51990 REM POKEVM routine ua = address ub = data uc = number of 
      copies
51995 REM Calculate high and low byte of address and POKE down 
      data into POKEVM assembly routine
52000 uw = INT(ua/256): uy = ua-uw*256: uw =uw+64: POKE ux+6, uy:
      POKE ux-10, uw: POKE ux-20, ub: POKE ux-4, INT(uc/256)
52010 REM Set timing for VDP access
52020 POKE 17009,0
52100 POKE ux-3, uc-INT(uc/256)*256: CALL ux

Page - 10

52200 RETURN
52990 REM Screen write ur = row ul = column ub = data uc = number 
      of copies
52995 REM Calculate VDP address for both screen tables
53000 us = ((ur-l)*32+ul-l)+2048: GOSUB 52000: ua = ua+4096: 
      GOSUB 52000: RETURN
53990 REM Define character us=ASCII code us$=character definition
      shorthand code
54000 TDR ui = 1 TO 16 STEP 2
54005 REM Decompose shorthand string into 8 bytes and POKEVM into 
      character table
54010 ul = ASC(MID$(us$, ui, 1))
54020 u2 = ASC(MID$(us$, ui+1, 1))
54030 IF ul < 60 THEN ul = ul - 48: 	GOTO 54050
54040 ul = ul-55
54050 IF u2 < 60 THEN u2 = u2-48: 	GOTO 54070
54060 u2 = u2-55
54070 ub = ul*16+u2: ua = (ui+1)/2+us*8-1: uc = 1: GOSUB 52000
54080 NEXT ui
54090 RETURN
54990 REM Color definition us = character set # uf =  foreground 
      color ub = background color
55000 ua = us+8191: ub = uf*16+ub: uc = 1: GOSUB 52000: RETURN
55990 REM PEEKV ua = address ub = incoming data
55995 REM Set timing for VDP access
56000 POKE 17009,0
56095 REM  Decompose address into two bytes and PORE  down  into 
      PEEKV assembly language
56100 uw = INT(ua/256):  uy = ua-uw*256:  POKE ux+33,  uy:  POKE 
      uX+37, uw: CALL ux+31: ub = PEEK(ux+55): RETURN
56990 REM Change screen color uc = color code
57000 ua = 18176+us:  POKE ux+16, 24: POKE 	ux+17, 10: GOSUB 
      52000: POKE ux+16, 227: POKE ux+17, 227: RETURN
57990 REM Character read from screen ur = row ul = column ub = data
58000 ua = ((ur-1)*32+ul-1)+6l44: 	GOSUB 56000: RETURN
65535 REM THIS IS A BUFFER FOR THE ASSEMBLY LANGUAGE ROUTINE

EXAMPLE PROGRAMS

This example demonstrates the POKEVM and PEEKV  subroutines.  The 
program  changes the definition of characters 32-255 so that  the 
characters appear upside down.

 90 REM set up assembly language
100 GOSUB 51000
105 REM Loops through the character table starting with ASCII 
    (32) times 8 which equals 256.
110 FOR I + 256 TO 2048 STEP 8
115 co = 0
116 REM Reads the 8 bytes that define the character in VDP memory
120 FOR m = I TO i+7
130 ua = m: GOSUB 56000: te(co) = ub
150 co = co+1
160 NEXT m
170 co=0
175 REM Invert and POKEV the character definition back to VDP 
    memory.
180 FOR m = I+7 TO I STEP -1
190 us = m: ub = te(co): uc = 1: GOSUB 52000
200 co = co+1
210 NEXT m
220 NEXT i
230 END

PUT UTILITIES HERE....

This example program illustrates how to define a character.  This 
program changes the character "A" to look like a jet.

90  REM setup assembly language
100 GOSUB 51000
110 us = 65: us$ = "08l93BFF3B190800": 	GOSUB 54000
120 PRINT "A A A A A A A A A A A A A A"
140 END

PUT UTILITIES HERE....

Page - 11

This  example program demonstrates several of the VDP  utilities. 
it  demonstrates redefining characters and placing that character 
on the screen. The program will create a little man and cause him 
to dance back and forth across the screen.

90 REM Set up assembly routine
100 GOSUB 51000
105 REM Shorthand character definition code for little man
110 a$ = "1898FF3D3CE40400"
120 b$ = "1819FFBC3C272000"
125 REM Redefine characters 0 and 1
130 us = 0: us$ = a$: GOSUB 54000
140 us = 1: us$ = b$: GOSUB 54000
145 REM Use screen write subroutine 	to clear screen
150 ur = 1: ul = 1: ub = 32: uc = 768: GOSUB 53000
160 b = 2: c = 31: e = 1: fl = 0
165 REM Loop to locate man on screen
170 FOR I = b TO c STEP e
175 REM Alternate between character 0 and 1
180 IF fl = 0 THEN fl = 1: GOTO, 210
190 fl = 0
200 REM Erase character behind little man.  man is in row 10
210 ur = 10: ul = i-e: ub w 32: uc = 1: GOSUB 53000
212 REM Put man on screen in row 10
215 ur = 10: ul = i: ub = fl: uc = 1: GOSUB 53000
220 NEXT i
225 REM Mange directions
230 IF c = 31 THEN b = 31: c = 2: e = 1: GOTO 170
240 GOTO 160
250 END

PUT UTILITIES HERE.

This program demonstrates how to read characters from the screen. 
The program reads the screen into an array buffer and than prints 
the screen in reverse order.

90 REM List some TEXT on the screen
100 LIST 100-400
105 REM Set up assembly language
110 GOSUB 51000
120 DIM b$(24)
125 REM Read screen and put into array buffer
130 FOR ro = 24 TO 1 STEP -1
140 FOR co = 2 TO 31
150 ur = ro: ul = co: GOSUB 58000
160 b$(ro) = b$(ro)*CHR$(ub)
170 NEXT co
180 NEXT ro
185  REM  Print the buffers back to 	the screen  in  reverse 
order
190 FOR ro = 24 TO 1 STEP -1
200 PRINT b$(ro)
210 b$(ro) = ""
220 NEXT ro
230 END

PUT UTILITIES HERE

This program flashes all the different color screens.

90 REM get up the assembly routine
100 GOSUB 51000
105 REM Loop through the different colors
110 FOR I = 0 TO 15
120 uc = i: GOSUB 57000
125 REM Delay loop
130 FOR i = 0 TO 500: NEXT i
140 NEXT i
150 GOTO 110

PUT UTILITIES HERE.....

The  following  program helps you obtain the shorthand  code  for 
defining your own characters.

When  you  RUN this program an 8 x 8 grid will be  displayed  for 
you.  By  pressing  the "1" key a black square will  replace  the 
cursor  and the cursor will move to the next  position.  Pressing 
the key "0" will leave the square blank. After the last square is 
defined  the  shorthand code string will be displayed  along  the 
real size character by itself and in a 3 x 3 square. If you make

Page - 12

a mistake Before you define the last square you can use the right 
and left arrow key to position yourself to make the correction.

After  the character code is displayed you have a choice to  quit 
or  to define another character.  if you choose to  continue  the 
scram will be cleared and a new 8 x a grid will be displayed. The 
image  of the last 8 x I grid can be recovered by Just using  the 
arrow  key to pass the cursor over the grid.  Because of this  if 
you  have  made  an error an the previous character grid  it  can 
easily be corrected an the next grid.

This  program was modified from a program originally written  for 
the  TI  99/4(A)  home  computer The  TI  99/4(A)  and  the  ADAM 
computers both have the same VDP processor. with the utilities we 
have   provided  in  this  newsletter  and  utilities  of  future 
newsletters you can modify many of the TI 99/4(A) programs to run 
on the ADAM system.

90 GOSUB 51000
95 REM Change color of screen
100 uc = 4: GOSUB 57000
103 REM Redefine characters 30, 100, 101
105 us = 30: Us$ = "FF81818181818181FF": GOSUB 54000
110 DIM b(8, 8)
120 us = 100: us$ = "000000000000000000": GOSUB 54000
130 us = 101: us$ ="FFFFFFFFFFFFFFFFFF": GOSUB 54000
135 REM Change color of set 13, 4, 16
140 us = 13: uf = 1: ub = 15: GOSUB 55000
145 us = 4: uf = 15: ub = 9: GOSUB 55000
147 us = 16: uf = 4: ub = 4: GOSUB 55000
148 REM Clear screen
150 ur = 1: ul = 1: ub = 32: uc = 	768: GOSUB 53000
155 REM Create screen
160 m$ = "AUTO CHARACTER DEFINITION"
170 y = 3
180 x = 4
190 GOSUB 770
200 m$ = "12345678"
210 y = 8
220 GOSUB 770
230 GOSUS 820
240 m$ = "O=OFF=WHITE"
250 y = 22
260 x = 4
270 GOSUB 770
280 m$ = "1=ON=BLACK"
290 y = 23
300 GOSUB 770
310 FOR r = 1 TO 8
320 ur = 8+r: ul = 5: ub = 100: uc = 	8: GOSUB 53000
330 NEXT r
335 REM Cursor control on 8 x 8 grid
340 FOR r = 1 TO 8
330 FOR c = 1 TO 8
360 ur = 8+r: ul = 4+c: ub = 30: uc = 1: GOSUB 53000
370 GET ka$: ke = ASC(ka$)
380 IF ke = 163 OR ke = 161 THEN 400
390 GOTO 420
400 GOSUB 870
410 GOTO 360
420 ke = ke-48
430 If (ke < 0) OR (ke > 1) THEN 370
440 b(r, c) = ke
450 ur = 8+r: ul = 4+c: ub = 100*ka: 	uc = 1: GOSUB 53000
460 NEXT c
470 NEXT r
475 REM Create shorthand definition
480 he$ = "0123456789ABCDEF"
490 m$ = ""
500 FOR r = 1 TO 8
510 lo = b(r, 5)*8+b(r, 6)*4+b(r, 7)*2+b(r, 8)+l
520 hi = b(r, 1)*8+b(r, 2)*4+b(r, 3)*2+b(r, 4)+1
530 m$ = m$+MID$(he$, hi, 1)+MID$ (he$, lo, 1).
540 NEXT r
545 REM Display new characters and 	shorthand code
550 us = 102: us$ = m$: GOSUB 54000
560 ur = 8: ul = 20: ub = 102: uc = 	1: GOSUB 53000
570 FOR r = 0 TO 2
580 ur = 12+r: ul = 20: ub = 102: uc = 	3: GOSUB 53000
590 NEXT R
600 y = 16
610 x = 13
620 GOSUB 770
630 m$ = "PRESS q To QUIT"
640 y = 18
650 x = 12
660 GOSUB 770
670 m$ = "PRESS ANY OTHER"
680 y = 19
690 GOSUB 770

Page - 13

700 m$= "KEY TO CONTINUE"
710 y = 20
720 GOSUB 770
730 GET ka$: ke = ASC(ke$)
730 IF ke <> 113 THEN 140
760 TEXT: END
765 REM Horizontal string display routine
770 FOR i = 1 to LEN(m$)
780 co = ASC(MID$(m$, I 1))
790 ur = y: ul = x+i: ub = co: uc = 1: GOSUB 53000
800 NEXT I
810 RETURN
815 REM Vertical string display routine
820 FOR i = 1 To LEN(m$)
830 co = ASC(MID$(m$, i, 1))
840 ur = y+i: ul = x: ub = co: uc = 1: GOSUB 53000
830 NEXT i
860 RETURN
865 REM Arrow keys routine
870 ur = 8+r: ul = 4+c: ub = 100-b(r, c): uc = 1: GOSUB 53000
880 IF ke = 161 THEN 960
890 c = c-1
900 IF c <> 0 then 1020
910 c = 8
920 r = r-1
930 If r <> 0 then 1020
940 r = 8
950 GOTO 1020
960 c = c+1
970 IF c <> 9 then 1020
980 c = 1
990 r = r+1
1000 IF r <> 9 THEN 1020
1010 r = 1
1020 RETURN

MISCELLANEOUS TID-BITS

The purpose of this column is to inform you of interesting little 
pieces of information that are not big enough subjects to warrant 
an article on its own. It may be a bug in the ADAM's software, or 
a 14 little-known feature of SmartBasic,  a useful system routine 
that  can be CALL'ed from your Basic program,  or a nifty  little 
work-around for some nagging 'problem everyone seems to encounter.
  If  you have a neat trick 	would benefit others,  that  you 
think send it to us and we'll make sure you got credit for it.  ' 
Here's a couple I bet you aren't aware of....

If you have ever tried to POKE a value into a memory above 53630, 
you  know that it doesn't work.   first thought that it was  Read 
only memory.  Actually, its only because SmartBasic just won't do 
it for your protection.  The limit is stored in 16149 and  16150. 
It  you poke a value a 255 into both locations,  you will be able 
to do a POKE anywhere you like!

Did you ever notice that every time you save a Basic program, all 
the  REM and DATA statements grow by  one  character?  SmartBasic 
will  always add a space after the words REM and DATA.   YOU must 
be  very careful with our Utilities since the  assembly  language 
routines are contained in DATA statements and are very long. Save 
it  a few times you will first lose the 201 which is the  machine 
code  for RETURN.   To fix this situation,  list the-line on  the 
screen,  run the cursor over the line number, space over the DATA 
(or  REM) until you can retype the word in front of the  original 
data, then run the cursor over the rest of the line.

CLOSING REMARKS

SERENDIPITY hopes you found this issue enjoyable and educational. 
we  would  appreciate your comments regarding any aspect of  this 
publication.  if  you would like to see specific topics  covered, 
please  let  us  know and we'll try to  discuss  them  in  future 
issues. lastly, if you have any information about the ADAM system 
you  would  like to share with our readers,  please feel free  to 
send it to us.

Page - 14

Listing #2

PROGRAM POKEVM

DATE December 27, 1984

PURPOSE  Pokes  a  character into VDP memory  as  many  times  as 
desired.  The  destination  address,  character count  and  ASCII 
character code must be poked into this routine before execution.

Byte	Decimal		Op	Argument	Comments
Count	Values		
Code						
1	245		USH	AF	Store registers that
2	197		PUSH	BC	we will be using
3	1  0  0		D	BC $00	Character count
6	62  0		LD	A, $00	Low byte of destination
8	211  191	OUT	$BF,A	Send it to VDP
10	62  0		LD	A, $00	High byte of destination
12	211  191	OUT	$BF, A	Send it to VDP
14	227		EX	(SP), HL Time delay required by
15	227		EX	(SP), HL by VDP for address
16	227		EX	(SP), HL set up.
17	227		EX	(SP), HL1
8	227		EX	(SP), HL
19	227		EX	(SP), HL
20	62  0		LD	A, $00	Ascii code to be printed
22	211  190	OUT	$BE, A	Send data to VDP
24	121		DEC	BC	Decrement the count
25	120		LD	A, B	Load "B"into"A" to compare
26	177		OR	C	If count isn't zero then
27	32  247		R	NZ,$F7	go back through loop
29	193		POP	BC	Else restore registers
30	241		POP	AF	and return to BASIC
31	201		RET

Listing 03
PROGRAM 	PEEKV
DATE	December 27, 1984

PURPOSE - PEEKS  a character from VDP memory.  The  destination 
address must be poked into this routine before execution.

Byte	Decimal         Op	Argument	Comments
Count	Values	        Code					
1	245	        PUSH	AF		Store registers
2	62  0		LD	A, $00	Low byte of destination
4	211  191	OUT	$BF, A		Send it to VDP
6	62  0		LD	A, $00	High byte of destination
8	211  191	OUT	$BF, A		Send it to VDP
10	227		EX	(SP), HL  Time delay required by
11	227		EX	(SP), HL	set up.
12	227		EX	(SP), HL13  227	EX	(SP), HL
14	227		EX	(SP), HL15  227	EX	(SP), HL
16	219  190	IN	A, $BE	    Get data to VDP
18	50  0  0	LD($0000,A    Basic rtn. will supply this
21	241		POP	AF          Restore register and
22	201		RET		    return to Basic
age - 15
e  ADAM TECHNICAL JOURNAL is published bi-monthly by  Serendipity 
Productions.  Subscription rates are $15.00 per year in the  U.S. 
and  Canada,  $20.00  per year in any other country,  payable  by 
check or money order only. Single issues are available for $3.00. 
All  inquiries  and  payments  should  be  made  to   Serendipity 
Productions, P.C. Box 07592t Milwaukee, WX 53207.
Preview of the next issue:

Making the most out of hi-res graphics.

Defining and moving graphics Sprites for animation.

Using the joysticks for graphics motion control

The  second installation of the Basic Utility Library  containing 
all the sprite control utilities

All  concepts  are demonstrated in an example program which  does 
free-hand screen painting with the joystick.

More useful Tid-Bits of information.
